package net.gxnun.xiaoyuan.core.business.share;

import java.util.ArrayList;
import java.util.List;


public class MenuTree {
    
    private List<MenuTreeNode> treeNodeList = new ArrayList<MenuTreeNode>();
    
    private static MenuTree instance = null;
    
    public static MenuTree getInstance(){
        if(instance == null){
            instance = new MenuTree();
        }
        return instance;
    }
    
    private MenuTree(){
        MenuTreeNode node = new MenuTreeNode();
        node.setDescription("欢迎使用便利校园微信公众号!");
        node.setId(0);
        node.setParentId(0);
        treeNodeList.add(node);
        
        MenuTreeNode node1 = new MenuTreeNode();
        node1.setDescription("子节点1!");
        node1.setId(1);
        node1.setParentId(0);
        treeNodeList.add(node1);
        
        MenuTreeNode node2 = new MenuTreeNode();
        node2.setDescription("子节点2!");
        node2.setId(2);
        node2.setParentId(0);
        treeNodeList.add(node2);
        
        MenuTreeNode node3 = new MenuTreeNode();
        node3.setDescription("子节点3!");
        node3.setId(3);
        node3.setParentId(1);
        treeNodeList.add(node3);
        
        MenuTreeNode node4 = new MenuTreeNode();
        node4.setDescription("子节点4!");
        node4.setId(4);
        node4.setParentId(1);
        treeNodeList.add(node4);
    }
    
    //获取某个结点的隶属子节点
    public List<MenuTreeNode> getChildren(int parentId){
        List<MenuTreeNode> nodeList = new ArrayList<MenuTreeNode>();
        for(MenuTreeNode node : treeNodeList){
            if(node.getParentId()==parentId){
                nodeList.add(node);
            }
        }
        return nodeList;
    }
    
    
}
